<% # @page_title="Credentials" %>
<% @mselect_creds=1 %>
<% @table = @credentials %>
<% @action = "index" %>
<% @cont = "credentials" %>

<%= render :partial => 'layouts/page_count' %>

<table>
<thead>
  <tr>
    <th scope="col">
      <%= sort_link("Area", "session_test_area") %>
      <%= filterx_icon("Remove filter on #{session[:test_area]}", session[:test_area], :test_area, {:controller => 'test_areas', :action => 'set', :id => 'all'}) %>
    </th>

    <th scope="col"><%= sort_link("Type", "type") %>
      <%= filterx_icon("Remove filter on port #{@url_params[:type_v]}", @url_params[:type_v], :type_v, {:controller => @cont}) %>
    </th>

    <th scope="col"><%= sort_link("Dom", "domain") %>
      <%= filterx_icon("Remove filter on host", @url_params[:domain_v], :domain_v, {:controller => @cont}) %>
    </th>

    <th scope="col"><%= sort_link("Host", "ip_address") %>
      <%= filterx_icon("Remove filter on host", @url_params[:host_id_v], :host_id_v, {:controller => @cont}) %>
    </th>

    <th scope="col"><%= sort_link("Port", "port") %>
      <%= filterx_icon("Remove filter on port #{@url_params[:port_v]}", @url_params[:port_v], :port_v, {:controller => @cont}) %>
    </th>

    <th scope="col"><%= sort_link("Username", "username") %>
      <%= filterx_icon("Remove filter on port #{@url_params[:username_v]}", @url_params[:username_v], :username_v, {:controller => @cont}) %>
    </th>

     <th scope="col"><%= sort_link("Password", "password") %>
      <%= filterx_icon("Remove filter on port #{@url_params[:password_v]}", @url_params[:password_v], :password_v, {:controller => @cont}) %>
    </th>

  </tr>
</thead>

<tbody>
<%
odd_or_even = 0
for credential in @credentials
    odd_or_even = 1 - odd_or_even
%>
  <tr class="odd<%=h odd_or_even %>">
    <% if credential.port_id? then %>
      <td><%=h credential.port.host.test_area_name %>
        <%= filter_icon("Show only #{credential.port.host.test_area_name}", session[:test_area], {:controller => 'test_areas', :action => 'set', :id => credential.port.host.test_area_id}) %>
      </td>
    <% else %>
      <td><%=h credential.test_area_name %>
        <%= filter_icon("Show only #{credential.test_area_name}", session[:test_area], {:controller => 'test_areas', :action => 'set', :id => credential.test_area_id}) %>
      </td>
    <% end %>

    <td>
        <%=h credential.credential_type_name %>
        <%= filter_icon("Show only #{credential.credential_type_name}", @url_params[:type_v], {:controller => 'credentials', :type_v => credential.credential_type_name}) %>
    </td>

    <td>
    <% if credential.domain? then %>
        <%=h credential.domain %>
        <%= filter_icon("Show only #{credential.domain}", @url_params[:domain_v], {:controller => 'credentials', :domain_v => credential.domain}) %>
    <% else %>
        <i>N/A</i>
    <% end %>
    </td>

    <td>
        <%= link_to_host(credential.ip_address, {:controller => 'hosts', :action => 'showcreds', :id => credential.host_id}) %>    
        <%= filter_icon("Show only #{credential.ip_address}", @url_params[:host_id_v], {:controller => 'credentials', :host_id_v => credential.host_id}) %>
    </td>

    <% if credential.port_id? then %>
      <td><%=h credential.port.port %>/<%=h credential.transport_protocol_name %>
        <%= filter_icon("Show only #{credential.port.port}", @url_params[:port_v], {:controller => 'credentials', :port_v => credential.port.port}) %>
      </td>
    <% else %>
      <td><i>N/A</i></td>
    <% end %>

    <% if credential.username? then %>
      <td><%=h credential.username %>
        <%= filter_icon("Show only #{credential.username}", @url_params[:username_v], {:controller => 'credentials', :username_v => credential.username}) %>
      </td>
    <% else %>
      <td><i>N/A</i></td>
    <% end %>

    <% if credential.password.nil? then %>
      <td><i>unknown</i></td>
    <% else %>
      <% if credential.password.empty? then %>
        <td><i>Blank!</i></td>
      <% else %>
        <td><%=h credential.password %>
          <%= filter_icon("Show only #{credential.password}", @url_params[:password_v], {:controller => 'credentials', :password_v => credential.password}) %>
        </td>
      <% end %>
    <% end %>
  </tr>
<% end %>
</tbody>
</table>

<%= render :partial => 'layouts/page_count' %>
<i>Note: Apparently duplicate entries in the table are most commonly caused by each username <p>
having a LANMAN and NTLM hash in the backend.</i>
